package com.celeritymq.server.configuration;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

public class XmlFileReader {
	//请务必将所有配置文件都放入classpath中
	private static final String CLASS_PATH=System.getProperty("java.class.path");
	private static SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
	private File file;
	XmlFileReader(String fileName)throws ParserConfigurationException, SAXException, IOException{
		this.file=new File(CLASS_PATH+File.separator+fileName);
		if(!file.exists()){
			throw new FileNotFoundException(fileName+" does not exsit!");
		}
		SAXParser saxParser=saxParserFactory.newSAXParser();
		XMLReader xmlReader=saxParser.getXMLReader();
		xmlReader.setContentHandler(null);
		xmlReader.parse(new InputSource(file.getAbsolutePath()));
	}
	//test
	public static void main(String[] args){
		File f=new File("d:"+File.separator+"0812-10-1440.jpg");
		System.out.println(f.getPath());
		
	}
	
}
